#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "hitten.h"
#include <QKeyEvent>
#include "QTime"
#include <QDebug>

static int sum=0;// 静态变量，计算达到冲鸭的次数

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{

    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::chushihua() //初始化每天状态为萌混过关
{

    ic1.index=2;
    ic2.index=2;
    ic3.index=2;
    ic4.index=2;
    ic5.index=2;
    gengxin();
}


void MainWindow::end ()//判断每一天是否到达冲鸭的状态,或者是否超出ddl
{

    for(int i=0;i<5;i++)
    {
        if(state[i]==3)
            sum++;
    }
    if(sum>=10)
    {
        //this->close();//目标达成，游戏结束//
    }


}

void MainWindow::suijinum()  //随机给一或多个天数给出冲鸭状态
{
    qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
    int all=qrand()%3+1;
    for(int i=0; i<all; i++)
    {
        int temp =qrand()%5+1;
        switch (temp) {
        case 1: ic1.index=0;
            break;
        case 2: ic2.index=0;
            break;
        case 3: ic3.index=0;
            break;
        case 4: ic4.index=0;
            break;
        case 5: ic5.index=0;
            break;

        }
       // qDebug()<<temp;
    }
    gengxin();
}

void MainWindow::gengxin() //实现更新图片功能
{
    QPixmap g1(ic1.images[ic1.index]);
    ui->p1->setPixmap(g1);
    ui->p1->show();
    QPixmap g2(ic2.images[ic2.index]);
    ui->p2->setPixmap(g2);
    ui->p2->show();
    QPixmap g3(ic3.images[ic3.index]);
    ui->p3->setPixmap(g3);
    ui->p3->show();
    QPixmap g4(ic4.images[ic4.index]);
    ui->p4->setPixmap(g4);
    ui->p4->show();
    QPixmap g5(ic5.images[ic5.index]);
    ui->p5->setPixmap(g5);
    ui->p5->show();
    end();
}

void MainWindow::on_pushButton_1_clicked()
{
        QPixmap zou(ic1.NextImage());
        state[0]=ic1.index;
        //qDebug()<<ic1.index;
        ui->p1->setPixmap(zou);
        ui->p1->show();
        end ();
}

void MainWindow::on_pushButton_3_clicked()
{
    QPixmap zou(ic2.NextImage());
    state[1]=ic2.index;
    ui->p2->setPixmap(zou);
    ui->p2->show();
    end();
}

void MainWindow::on_pushButton_5_clicked()
{
    QPixmap zou(ic3.NextImage());
    state[2]=ic3.index;
    ui->p3->setPixmap(zou);
    ui->p3->show();
    end();
}

void MainWindow::on_pushButton_clicked()
{
    QPixmap zou(ic4.NextImage());
    state[3]=ic4.index;
    ui->p4->setPixmap(zou);
    ui->p4->show();
    end();
}

void MainWindow::on_pushButton_2_clicked()
{
    QPixmap zou(ic5.NextImage());
    state[4]=ic5.index;
    ui->p5->setPixmap(zou);
    ui->p5->show();
    end();
}
